<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="org.example.entity.Person" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>投票系统 - 历史记录</title>
    <!-- 引入Layui CSS -->
    <%--    <link rel="stylesheet" href="../../css/layui.css">--%>
    <script src="../../js/layui.js"></script>
    <link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.8.17/css/layui.min.css">
    <script src="../../js/jquery-3.7.1.min.js"></script>
    <!-- 引入Font Awesome -->
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <style>
        /* 响应式调整 */
        @media (max-width: 768px) {
            .admin-container {
                padding: 20px 15px;
            }

            .layui-tab-title {
                padding: 0 15px;
            }

            .layui-tab-title li {
                padding: 0 15px;
                font-size: 15px;
            }

            .module-header {
                padding: 20px 15px 10px;
            }

            .module-title {
                font-size: 18px;
            }

            .theme-cards, .admin-table {
                padding: 15px;
            }

            .theme-card {
                border-radius: 12px;
            }

            .card-image {
                height: 150px;
            }

            .admin-table th, .admin-table td {
                padding: 15px 12px;
                font-size: 13px;
            }

            .pagination li a {
                padding: 8px 12px;
                font-size: 13px;
            }
        }

        /* 卡片式布局样式 */
        .theme-cards {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
            gap: 24px;
            padding: 30px;
        }

        .theme-card {
            background-color: #fff;
            border-radius: 14px;
            overflow: hidden;
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            display: flex;
            flex-direction: column;
            height: 100%;
        }

        .theme-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
        }

        .card-image {
            width: 100%;
            height: 180px;
            object-fit: cover;
            transition: transform 0.5s ease;
        }

        .theme-card:hover .card-image {
            transform: scale(1.03);
        }

        .card-content {
            padding: 20px;
            flex-grow: 1;
            display: flex;
            flex-direction: column;
        }

        .card-status {
            display: inline-block;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 600;
            margin-bottom: 12px;
            white-space: nowrap;
        }

        .status-running {
            background-color: rgba(30, 159, 255, 0.1);
            color: #1E9FFF;
        }

        .status-not-started {
            background-color: rgba(126, 136, 149, 0.1);
            color: #7E8895;
        }

        .status-finished {
            background-color: rgba(220, 53, 69, 0.1);
            color: #dc3545;
        }

        .status-deleted {
            background-color: rgba(220, 53, 69, 0.1);
            color: #676767;
        }

        .card-title {
            font-size: 18px;
            font-weight: 600;
            margin-bottom: 12px;
            color: #333;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }

        .card-meta {
            display: flex;
            flex-direction: column;
            gap: 8px;
            margin-bottom: 20px;
            color: #666;
            font-size: 14px;
        }

        .meta-item {
            display: flex;
            align-items: center;
        }

        .meta-item i {
            color: #999;
            margin-right: 8px;
            width: 18px;
            text-align: center;
        }

        .card-actions {
            display: flex;
            gap: 10px;
            margin-top: auto;
        }

        .card-actions button {
            background-color: transparent;
            border: 1px solid #e0e2e5;
            cursor: pointer;
            padding: 8px 12px;
            border-radius: 6px;
            transition: all 0.2s ease;
            display: flex;
            align-items: center;
            font-size: 13px;
            flex-grow: 1;
            justify-content: center;
        }

        .card-actions .edit-btn {
            color: #1E9FFF;
            border-color: #d0e8ff;
        }

        .card-actions .edit-btn:hover {
            background-color: #e6f2ff;
            border-color: #a8d5ff;
        }

        .card-actions .delete-btn {
            color: #dc3545;
            border-color: #f8d7da;
        }

        .card-actions .delete-btn:hover {
            background-color: #fce9eb;
            border-color: #f5c2c7;
        }

        body {
            background-color: #f8f9fa;
            margin: 0;
            padding: 0;
            font-family: 'Helvetica Neue', Arial, sans-serif;
        }

        .header {
            background-color: #ffffff;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
            padding: 15px 30px;
            display: flex;
            align-items: center;
        }

        .header a {
            color: #333;
            margin-left: 25px;
            text-decoration: none;
            transition: color 0.3s ease;
            font-size: 15px;
        }

        .header a:hover {
            color: #1E9FFF;
        }

        .header > a:first-child {
            margin-left: 0;
        }

        .ml-auto {
            margin-left: auto;
        }

        /* 分页样式 */
        .pagination-container {
            display: flex;
            justify-content: center;
            margin: 30px 0;
        }

        .pagination {
            display: inline-flex;
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .pagination li {
            margin: 0 5px;
        }

        .pagination li a {
            display: inline-block;
            padding: 8px 14px;
            border-radius: 5px;
            text-decoration: none;
            color: #333;
            background-color: #f0f0f0;
            transition: all 0.3s ease;
        }

        .pagination li a:hover,
        .pagination li.active a {
            background-color: #1E9FFF;
            color: #fff;
        }

        /* 响应式调整 */
        @media (max-width: 768px) {
            .voteResult-container {
                padding: 30px 20px;
                grid-template-columns: 1fr;
            }

            .header {
                padding: 15px 20px;
            }

            .header a {
                margin-left: 20px;
                font-size: 14px;
            }

            .pagination li a {
                padding: 6px 10px;
            }
        }
    </style>
</head>
<body>
<nav class="header">

    <c:if test="${person.level == 1}">
        <a href="${pageContext.request.contextPath}/person/index" class="flex items-center">
            <i class="fa fa-home text-primary text-xl mr-2"></i>
            <span class="font-bold text-lg">用户首页</span>
        </a>
        <a href="${pageContext.request.contextPath}/admin/index" class="flex items-center">
            <i class="fa fa-home text-primary text-xl mr-2"></i>
            <span class="font-bold text-lg">管理员首页</span>
        </a>
    </c:if>
    <c:if test="${person.level == 0}">
        <a href="${pageContext.request.contextPath}/person/index" class="flex items-center">
            <i class="fa fa-home text-primary text-xl mr-2"></i>
            <span class="font-bold text-lg">用户首页</span>
        </a>
        <a href="${pageContext.request.contextPath}/history/show">投票历史</a>
        <a href="${pageContext.request.contextPath}/views/relation.jsp">联系管理员</a>
    </c:if>

    <div class="ml-auto flex items-center">
        <c:if test="${person == null}">
            <a href="${pageContext.request.contextPath}/views/login.jsp"><i class="fa fa-user-circle mr-2"></i>请先登录</a>
        </c:if>
        <c:if test="${person != null}">
            <a href="${pageContext.request.contextPath}/admin/person/editPerson?pid=${person.pid}"><i
                    class="fa fa-user-circle mr-2"></i>${person.username}</a>
        </c:if>


        <a href="javascript:void(0);" onclick="logout()">退出登录</a>
    </div>
</nav>

<!-- 主题卡片区域 -->
<div class="theme-cards">
    <!-- 主题卡片：已结束 -->
    <c:forEach var="topic" items="${sessionScope.history}">
        <div class="theme-card" onclick="voteResultHistory(${topic.tid},${topic.status})">
            <img src="${pageContext.request.contextPath}${topic.url}" alt="${topic.title}"
                 class="card-image">
            <div class="card-content">
                    <%-- 0 未开始，1.正在进行 2. 已结束 3.删除（不显示）--%>
                <c:if test="${topic.status == 0}">
                    <span class="card-status status-not-started">未开始</span>
                </c:if>
                <c:if test="${topic.status == 1}">
                    <span class="card-status status-running">进行中</span>
                </c:if>
                <c:if test="${topic.status == 2}">
                    <span class="card-status status-finished">已结束</span>
                </c:if>
                <h3 class="card-title">${topic.title}</h3>
                <div class="card-meta">
                    <div class="meta-item"><i class="fa fa-user"></i> 创建者：${topic.author}</div>
                    <div class="meta-item"><i class="fa fa-calendar"></i> ${topic.beginDate}
                        至 ${topic.endDate}</div>
                </div>
            </div>
        </div>
    </c:forEach>
</div>


<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form;
        var layer = layui.layer;

        // 退出登录功能
        document.querySelector('.header a:last-child').addEventListener('click', function () {
            layer.confirm('确定要退出登录吗？', {
                icon: 3,
                title: '提示'
            }, function (index) {
                // 这里添加退出登录的实际逻辑
                layer.msg('已成功退出登录', {icon: 1});
                setTimeout(function () {
                    // 跳转到登录页面
                    window.location.href = '/VoingSystem/logout';
                }, 1500);
                layer.close(index);
            });
        });


    });

    function logout() {
        layer.confirm('确定要退出登录吗？', {
            icon: 3,
            title: '提示'
        }, function (index) {
            // 这里添加退出登录的实际逻辑
            layer.msg('已成功退出登录', {icon: 1});
            setTimeout(function () {
                window.location.href = '${pageContext.request.contextPath}/logout';
            }, 1500);
            layer.close(index);
        })
    }

    function voteResultHistory(tid, status) {
        if (status == 1) {
            window.location.href = '${pageContext.request.contextPath}/history/show/info?tid=' + tid;
        } else if (status == 0) {
            layer.msg('投票尚未开始', {icon: 5})
        } else {
            layer.msg('投票已结束', {icon: 5})
        }
    }
</script>
</body>
</html>